Skip to content

Avoid redundant allocations#620

Closed
qwwdfsad wants to merge 3 commits into
facebook:mainfrom
qwwdfsad:optimize-redundant-memory
Closed

Avoid redundant allocations#620
qwwdfsad wants to merge 3 commits into
facebook:mainfrom
qwwdfsad:optimize-redundant-memory

Conversation

@qwwdfsad

Copy link
Copy Markdown
Contributor
  • Optimizes work with PsiElement: no direct text access where appropriate as it's relatively expensive
  • Some early returns to avoid String copying when it is not necessary
  • Around 6-7% performance improvements on my machine on sequential kotlinx.coroutines runs (5 -> 4.65 sec in sequantial mode)

Partially addresses #619

qwwdfsad added 2 commits May 30, 2026 22:56
* Most of the PsiElements are composites with an expensive text query, and they are skipped anyway
* Use token type instead of text matching where appropriate
* Use PsiElement.textContains(char) where appropriate
* No semantic changes, total performance improvement is around ~6%
@meta-cla

meta-cla Bot commented May 30, 2026

Copy link
Copy Markdown

Hi @qwwdfsad!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@qwwdfsad

Copy link
Copy Markdown
Contributor Author

@AbdullinAM PTAL

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label May 30, 2026
@meta-cla

meta-cla Bot commented May 30, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@hick209

hick209 commented May 30, 2026

Copy link
Copy Markdown
Contributor

Could you update the CHANGELOG.md?

@qwwdfsad

Copy link
Copy Markdown
Contributor Author

Sure, done

@meta-codesync

meta-codesync Bot commented May 31, 2026

Copy link
Copy Markdown

@hick209 has imported this pull request. If you are a Meta employee, you can view this in D107013190.

@AbdullinAM AbdullinAM left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! Note for the future: we should add some benchmarks in this repo, to track these kind of performance gains

@cortinico cortinico left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review automatically exported from Phabricator review in Meta.

@meta-codesync

meta-codesync Bot commented Jun 1, 2026

Copy link
Copy Markdown

@hick209 merged this pull request in 2520d34.

@hick209 hick209 linked an issue Jun 17, 2026 that may be closed by this pull request
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Low-hanging fruits in ktfmt performance

4 participants